<template>
  <lb-layout
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
    :paddBottom="5"
  >
    <div class="head">
      <span class="title">{{ deptName }}-{{ year }}年费水统计</span>
      <el-tag type="success">合计部门：{{ allNum }}家</el-tag>
      <el-tag type="success" size="medium">计量单位：kgCO2</el-tag>
      <el-button @click="goBack" size="small">返回</el-button>
    </div>
    <el-table
      border
      height="700"
      v-loading="loading"
      :data="dataList"
      row-key="deptId"
      :default-expand-all="isExpandAll"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column
        prop="deptName"
        label="部门名称"
        min-width="200"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        prop="total"
        label="总碳排放量"
        show-overflow-tooltip
        align="center"
        width="150"
      >
        <!-- <template slot-scope="scope">
          <div>{{ scope.row.energyElectricity | numDealfilters }}</div>
        </template> -->
      </el-table-column>
      <el-table-column
        prop="month1"
        label="一月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month2"
        label="二月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month3"
        label="三月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month4"
        label="四月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month5"
        label="五月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month6"
        label="六月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month7"
        label="七月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month8"
        label="八月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month9"
        label="九月"
        show-overflow-tooltip
        align="center"
        min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month10"
        label="十月"
        show-overflow-tooltip
        align="center"
        min-min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month11"
        label="十一月"
        show-overflow-tooltip
        align="center"
        min-min-width="100"
      >
      </el-table-column>
      <el-table-column
        prop="month12"
        label="十二月"
        show-overflow-tooltip
        align="center"
        min-min-width="100"
      >
      </el-table-column>
    </el-table>
  </lb-layout>
</template>

<script>
import { deepClone, dealElectricity } from "@/utils/index";
import { getCarbonStatisticsMonth } from "@/api/carbon/index.js";
export default {
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      isExpandAll: true,
      dataList: [],
      deptId: null,
      year: "",
      backMenu: "",
      deptName: "",
      allNum: 0,
    };
  },
  created() {},
  mounted() {
    this.judgeRoute();
  },
  filters: {
    numDealfilters(num) {
      let result;
      let num1;
      if (typeof num == "string") {
        num1 = Number(num);
      } else {
        num1 = num;
      }
      result = dealElectricity(num1, 1, 2);
      return result;
    },
  },
  methods: {
    judgeRoute() {
      let route = this.$route;
      this.backMenu = route.meta.activeMenu;
      this.deptId = route.query.deptId;
      this.year = route.query.year;
      this.deptName = route.query.deptName;
      this.initData();
    },
    goBack() {
      // this.$router.push({
      //   path: this.backMenu,
      //   query: {},
      // });
      this.$router.go(-1);
    },
    initData() {
      let query = {
        deptId: this.deptId,
        year: this.year,
      };
      getCarbonStatisticsMonth(query)
        .then((res) => {
          this.loading = false;
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          let allCar = res?.data ?? {};
          this.allNum = allCar?.deptNum ?? 0;
          this.dataList = [allCar];
        })
        .catch(() => {
          // this.$message.error("系统错误,请联系管理员!");
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.head {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  .title {
    font-size: 28px;
    font-weight: 400;
  }
  .el-tag {
    margin-left: 20px;
  }
  .el-button {
    position: absolute;
    right: 20px;
  }
}
</style>
